# readme 条件控制 if
name = '小明'
age = 19
if age > 20:
    print("age is bigger than 20.")
elif age < 20:
    print("age is lower than 20.")
elif age == 18:
    print("age is equals 20.")
else:
    print("oh, age is error.")

age = 20
if age > 20:
    print("age is bigger than 20.")
else:
    if age == 20:
        print("age is 20.")
    elif age < 20:
        print("age is lower than 20")

# while 循环， 输出5遍
i = 0
while i < 5:
    i += 1
    print("Hello world: ", i)

# 计算累加 1到100的 和
i = 1
sum = 0
while i < 101:
    sum += i
    i += 1
print("sum is : ", sum)

# 嵌套while 循环
n = 5  # 5行
i = 1
while i <= n:
    j = 1
    while j <= i:  # 每行1-5个 *
        print("*", end=" ")
        j += 1
    print()
    i += 1

# while 循环 使用else 语句
age = 10
i = 1
while i < age:
    print("I am ", i, " years.")
    i += 1
else:
    print("else : I am ", 10, "years.")

# instr = 'n'
# while instr != 'y':
#     instr = input("是否退出程序（y / n） ：")
# else:
#     print("程序已退出。")

# 使用break 退出循环，使用continue跳过本次循环
n = 0
while n < 5:
    n += 1
    if n == 2:
        continue
    if n == 5:
        break
    print(n)

# for循环
for i in (1, 2, 3, 4, 5):
    print("i==", i)
else:
    print("退出for循环")

students = ['Jack', 'Tom', 'Alice']
for item in students:
    if item == 'Jack':
        continue
    if item == 'Alice':
        break
    print(item, end=" ")
print()

# for 循环 range函数
# 0  to  10，不包含10
for i in range(10):
    print(i, end=' ')
print()
# 1 to 11， 不包含11，  步长位1
for i in range(1, 11, 1):
    print(i, end=' ')
print()

# range生成集合
list1 = list(range(8))
print(list1)
list1 = list(range(1, 5))
print(list1)
list1 = list(range(1, 5, 2))
print(list1)

# 将字典转化为元祖进行遍历
dict1 = {'Tom': 18, 'Jack': 20, 'Alice': 19}
for key, value in dict1.items():
    print(key, ":", value)

for key in dict1:
    print(key, ":", dict1[key])

list1 = ['Tom','Jace','Alice']
for i in range(len(list1)):
    print(list1[i], end=" ")
print()